'use strict';

const Controller = require('egg').Controller;
const {getParam,postParam,renderTree} = require('../util/util.js');
class BillController extends Controller {
  /**
   * @description 核销单列表
   * @methods Get
  */
  async getBillList(){
    const { ctx } = this;
    const result = await ctx.service.bill.getList();
    console.log(result);
    if (result.length > 0) {
        ctx.body = {
            status:200,
            data:result,
            msg:"获取成功"
        };
    }else{
        ctx.body = {
            status:202,
            data:[],
            msg:"暂无数据"
        };
    }
    
  }
  /**
   * @descripttion 新增核销单
   * @methods Post 
   * @param billNum 账单号
  */
  async addBill(){
      const { ctx } = this;
      let billNum = getParam('billNum',ctx);   //核销单号
      let getTimp = Math.floor(new Date().valueOf()); //核销时间戳
      let optUser = ""; //操作员
      //先判断是否存在
      const result = await ctx.service.bill.addBill(billNum,getTimp,optUser)
      if(result.affectedRows == 1){
        ctx.body = {
            data:{},
            status:200,
            msg:"添加成功"
        }
      }else{
        ctx.body = {
            data:{},
            status:200,
            msg:"添加失败，请稍后重试"
        } 
      }
  }
  async deleteBill(){
      ctx.body = {
        data:{},
        status:200,
        msg:"删除成功，请稍后重试"
      }
  }
}
module.exports = BillController;